﻿using System;
using UnityEngine;

// Token: 0x020002C6 RID: 710
public class GiantessObstacleDetector : ObstacleDetector
{
	// Token: 0x06001086 RID: 4230 RVA: 0x00079530 File Offset: 0x00077730
	private void Start()
	{
		this.collisionDetector = new GameObject("Collision Detector").AddComponent<CollisionDetector>();
		this.collisionDetector.transform.SetParent(base.transform, false);
		this.collisionDetector.transform.localPosition = Vector3.forward * this.lookAhead;
	}

	// Token: 0x06001087 RID: 4231 RVA: 0x0007958C File Offset: 0x0007778C
	public override bool CheckObstacle()
	{
		if (this.walkingUp)
		{
			return false;
		}
		float time = Time.time;
		if (this.collisionDetector.isColliding)
		{
			return true;
		}
		if (time > this.nextCheck)
		{
			Vector3 position = base.transform.position;
			this.walkingUp = (position.y > this.last_y + this.step * this.scale);
			this.last_y = position.y;
			if (this.walkingUp)
			{
			}
			this.scale = base.transform.localScale.y;
			this.raycastDetected = this.CheckForWall();
			this.nextCheck = time + this.timeBetweenChecks;
		}
		return this.raycastDetected;
	}

	// Token: 0x06001088 RID: 4232 RVA: 0x0007964A File Offset: 0x0007784A
	public override Vector3 GetPoint()
	{
		if (this.collisionDetector.isColliding)
		{
			return this.collisionDetector.transform.position;
		}
		return this.raycastPoint;
	}

	// Token: 0x06001089 RID: 4233 RVA: 0x00079673 File Offset: 0x00077873
	public override Vector3 GetNormal()
	{
		if (this.collisionDetector.isColliding)
		{
			return -base.transform.forward;
		}
		return this.raycastNormal;
	}

	// Token: 0x0600108A RID: 4234 RVA: 0x0007969C File Offset: 0x0007789C
	private bool CheckForWall()
	{
		Vector3 vector = base.transform.position + base.transform.up * 200f * this.scale;
		Vector3 forward = base.transform.forward;
		float num = 1000f * this.scale;
		if (this.debugRays)
		{
			Debug.DrawLine(vector, vector + forward * num, Color.white, this.timeBetweenChecks);
		}
		RaycastHit raycastHit;
		if (Physics.Raycast(vector, forward, out raycastHit, num, Layers.gtsCollisionCheckMask))
		{
			this.raycastPoint = raycastHit.point;
			this.raycastNormal = raycastHit.normal;
			return !this.walkingUp;
		}
		return false;
	}

	// Token: 0x04001548 RID: 5448
	private CollisionDetector collisionDetector;

	// Token: 0x04001549 RID: 5449
	private bool debugRays = true;

	// Token: 0x0400154A RID: 5450
	private float lookAhead = 400f;

	// Token: 0x0400154B RID: 5451
	private bool raycastDetected;

	// Token: 0x0400154C RID: 5452
	private float nextCheck;

	// Token: 0x0400154D RID: 5453
	private float timeBetweenChecks = 1f;

	// Token: 0x0400154E RID: 5454
	private float scale;

	// Token: 0x0400154F RID: 5455
	private Vector3 raycastPoint;

	// Token: 0x04001550 RID: 5456
	private Vector3 raycastNormal;

	// Token: 0x04001551 RID: 5457
	private bool walkingUp;

	// Token: 0x04001552 RID: 5458
	private float last_y;

	// Token: 0x04001553 RID: 5459
	private float step = 0.05f;
}
